package com.centaline.androidsalesblog.rx.request;

import com.android.volley.VolleyError;
import com.centaline.androidsalesblog.api.newest.NewRegionApi;
import com.centaline.androidsalesblog.model.responseobject.NewRegionRo;
import com.centanet.framework.interfaces.IResponseListener;

import rx.Observable;
import rx.Subscriber;

/**
 * 新房区域
 * Created by guilin on 16/2/4.
 */
final class RequestNewRegionOnSubscribe implements Observable.OnSubscribe<NewRegionRo> {

    private final Class<?> tag;

    public RequestNewRegionOnSubscribe(Class<?> tag) {
        this.tag = tag;
    }

    @Override
    public void call(final Subscriber<? super NewRegionRo> subscriber) {
        new NewRegionApi(tag, NewRegionRo.class, new IResponseListener<NewRegionRo>() {
            @Override
            public void onResponse(NewRegionRo newRegionRo) {
                if (!subscriber.isUnsubscribed())
                    subscriber.onNext(newRegionRo);
                subscriber.onCompleted();
            }

            @Override
            public void onErrorResponse(VolleyError error) {
                subscriber.onError(error);
            }
        }).startRequest();
    }
}
